package com.sicheng.lc.周赛.分类.位运算;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/15 12:33
 */
public class 按位与结果大于零的最长组合 {
    //https://leetcode.cn/problems/largest-combination-with-bitwise-and-greater-than-zero/
    public int largestCombination(int[] candidates) {
        int[] bits = new int[25];
        for (int candidate : candidates) {
            for (int i = 0; candidate >> i > 0 && i < bits.length; i++) {
                if (((candidate >> i) & 1) == 1) {
                    bits[i]++;
                }
            }
        }
        int max = -1;
        for (int bit : bits) {
            max = Math.max(bit, max);
        }
        return max;

    }

    public static void main(String[] args) {
        按位与结果大于零的最长组合 solution = new 按位与结果大于零的最长组合();
        int[] nums = {16, 17, 71, 62, 12, 24, 14};
        System.out.println(solution.largestCombination(nums));
    }
}
